<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests\User\LoginRequest;
use Auth;




class LoginController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {


        //dd(get_class_methods(request()->route()) , request()->getRequestUri() , request()->route()->getName() , request()->route()->uri);
        //dd($this->test(2,3 , 4 , 5 , 6 , 7));

        return view('user.login.index');
    }

    public function test($aa , ...$b){

        print_r($b);
        return $aa ."_";
    }

    /**
     * 验证登陆
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(LoginRequest $request){

        $username = $request->username;
        filter_var($username , FILTER_VALIDATE_EMAIL) ?
            $credent['email']   = $username :
            $credent['account'] = $username;

        $credent['password'] = $request->password;


        if (auth()->attempt($credent , $request->has('remember'))){
            return response()->json([
                'code'=> 1,
                'msg' => '登陆成功',
            ]);
        }else{
            return response()->json([
                'code'=> 0,
                'msg' => '帐号密码错误',
            ]);
        }
    }


    /**
     * 退出登陆
     * */
    public function logout()
    {
        auth()->logout();

        return redirect()->route('zbsuser.login.index');
    }






}
